using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using MacomberMap.Common.User_Interfaces.Components;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
using MacomberMap.Common.User_Interfaces.One_Lines.Elements;
using MacomberMap.Common.Components;
using MacomberMap.Common.Types;
using MacomberMap.Common.Database_Interface;
namespace MacomberMap.Common.User_Interfaces.One_Lines.Elements
{
    /// <summary>
    /// This class provides a viewable Transformer
    /// </summary>
    public class MM_OneLine_Transformer : MM_OneLine_Element
    {
        #region Variable Declarations
        //TODO: Change category to "Data Linkages"
        /// <summary>
        /// The transformer windings associated with the element
        /// </summary>
        [Category("Element"), Description("The transformer windings associated with the element")]
        public MM_OneLine_TransformerWinding[] Windings        
        {
            get { return _Windings; }
            set { _Windings = value; }
        }
        private MM_OneLine_TransformerWinding[] _Windings = new MM_OneLine_TransformerWinding[2];
        #endregion



        #region Initialization
        /// <summary>
        /// Initialize a new viewable Transformer
        /// </summary>
        /// <param name="DisplayParameters">The display parameters for the control</param>
        public MM_OneLine_Transformer(MM_OneLine_Display DisplayParameters): base(DisplayParameters)
        {
        }

        /// <summary>
        /// Initialize a new viewable Transformer
        /// </summary>
        /// <param name="ElemConfig">The Xml configuration for the Transformer</param>
        /// <param name="DisplayParameters">The display parameters for the Transformer</param>
        /// <param name="DbConnection">The database connection</param>
        public MM_OneLine_Transformer(XmlElement ElemConfig, MM_OneLine_Display DisplayParameters, MM_Database DbConnection)
            : base(ElemConfig, DisplayParameters, DbConnection)
        {
            //Retrieve our arrow direction from the Transformer
            Orientation = ParseOrientation(ElemConfig.Attributes["Orientation"].Value);
                                                    
            //Import our windings
            List<MM_OneLine_TransformerWinding> OutWindings = new List<MM_OneLine_TransformerWinding>(ElemConfig.ChildNodes.Count);
            foreach (XmlElement xWind in ElemConfig.ChildNodes)
                if (xWind.Name == "Winding")
                    OutWindings.Add(new MM_OneLine_TransformerWinding(xWind));
            Windings = OutWindings.ToArray();
        }

        /// <summary>
        /// Initialize a new viewable Transformer
        /// </summary>
        /// <param name="BaseElement">The CIM element upon which the Transformer is based</param>
        /// <param name="DisplayParameters">The display parameters for the Transformer</param>
        /// <param name="Orientation">The orientation of the transformer</param>
        public MM_OneLine_Transformer(MM_Element BaseElement, MM_OneLine_Display DisplayParameters, MM_OneLine_Element.enumOrientations Orientation)
            : base(BaseElement, DisplayParameters, Orientation)
        {      
        }

      
        #endregion


        #region Rendering
        /// <summary>
        /// Draw the image for the transformer
        /// </summary>
        /// <param name="g"></param>
        public override void DrawImage(Graphics g)
        {
            foreach (MM_OneLine_TransformerWinding Winding in Windings)
                if (Winding != null)
                {
                    g.TranslateTransform(Winding.Bounds.Left, Winding.Bounds.Top);
                    Winding.DrawWinding(g);
                    g.TranslateTransform(-Winding.Bounds.Left, -Winding.Bounds.Top);
                }
                else
                    g.DrawRectangle(Pens.White, 0, 0, DisplayRectangle.Width - 1, DisplayRectangle.Height - 1);
        }        
        #endregion
    }
}


